import viewHeader from '@/components/view/common/Header'
import Col from 'view-design/src/components/col'
import N from '../skin/base'
import $ from 'jquery'

export default {
  name: 'OverView',
  data () {
    return {
      zhishi: '全量小区',
      zhiShiList: [
        {
        value: '全量小区',
        label: '制式'
        },
        {
          value: 'TDD',
          label: 'TDD'
        },
        {
          value: 'FDD900',
          label: 'FDD900'
        },
        {
          value: 'FDD1800',
          label: 'FDD1800'
        }
      ],
      zhanxing: '全量小区',
      zhanXingList: [
        {
          value: '全量小区',
          label: '站型'
        },
        {
          value: '宏站',
          label: '宏站'
        },
        {
          value: '室分',
          label: '室分'
        },
        {
          value: '微站',
          label: '微站'
        }
      ],
      shiduan: 'D',
      shiDuanList: [
        {
          value: 'D',
          label: '天'
        },
        {
          value: 'W',
          label: '周'
        },
        {
          value: 'M',
          label: '月'
        }],


      geography: '',
      geo_dim: '省',
      map_city: '',
      map_area: '全量小区',
      timeType: '天',
      // starttime: this.$utils.starttime(),
      city: '全省',
      dimensionType: '时间维度',
      result: {},
      type: '站型',
      scene_class: [],
      show: false,
      sceneNames: [],
      volte_voice_traffic: [], // VOLTE话务量（万Erl）
      upoct: [], // LTE数据流量（TB)
      starttime: [],
      geoDim: [], // 地理纬度子集列表
      HB_province: '河北省',
      volteVoiceTraffic_upoct_JSON: {},
      high_load_num: [], // 高负荷小区数
      basic_comm_complain_ratio: [], // 基础通信万投比
      mr_coverage_rate: [], // MR覆盖率
      poor_coverage_cell_ratio: [], // 弱覆盖小区占比
      critical_alarm_ratio: [], // 严重告警小区占比

      lte_users: [], // 4G客户数
      lte_users_dou: [], // 4G客户DOU

      radio_use_rate: [], // LTE无限利用率
      // 单小区流量和话务量
      upoct_aver: [],
      volte_voice_traffic_aver: [],

      wireless_access_rate: [],
      ho_succ_rate: [],
      wireless_dropcall_rate: [],

      wireless_access_1_rate: [],
      ho_succ_qci1_rate: [],
      erab_dropcall_1_rate: [],

      yemian_time: [], //          整体视频下载速率(kbps)
      starttime2: [],
      starttime1: [],
      geoDim1: [], // 地理纬度子集列表
      radio_equipment_availability: []// lte无线设备可用率
    }
  },
  components: {
    Col,
    viewHeader
  },
  methods: {
    pageInit: function (geography, shiduan, geo_dim, city, area) {
      // if (geography) {
      //   this.geographyChart(shiduan, geo_dim, city, area)
      // } else {
      //   this.timeChart(shiduan, geo_dim, city, area)
      // }
      // this.chartTop(shiduan, geo_dim, city, area)
    },
    getApiPath () {
      var obj = window.location
      return obj.protocol + '//' + obj.host + '/'
    },
    chartTop: function (shiduan, geo_dim, city, area) {
      if (geo_dim === '省') {
        this.param = {
          geo_dim: geo_dim,
          time_dim: shiduan,
          area: area,
          zhanxing: $('#zhanxing').val(),
          zhishi: $('#zhishi').val()
        }
      } else {
        this.param = {
          geo_dim: geo_dim,
          time_dim: shiduan,
          city: city,
          area: area,
          zhanxing: $('#zhanxing').val(),
          zhishi: $('#zhishi').val()
        }
      }
      this.param.isChartTop = 'true'
      this.$server.getData(
        'netWork/geographyChart', this.param
      ).then(res => {
        let res1 = res.a_pm_manager_view_widetable_new_list
        let a_pm_lte_app_manager_view_res_list = res.a_pm_lte_app_manager_view_res_list
        let a_pm_lte_manager_view_list = res.a_pm_lte_manager_view_list
        try {
          this.setBaseVal(a_pm_lte_manager_view_list)
          this.setBaseVal1(res1)
          this.setBaseVal2(a_pm_lte_app_manager_view_res_list)
        } catch (e) {
          console.log(e)
        }
      }).catch(function (e) {
        console.log(e)
        return false
      })
    },
    geographyChart: function (shiduan, geo_dim, city, area) {
      if (geo_dim === '省') {
        this.param = {
          geo_dim: '地市',
          time_dim: shiduan,
          area: area,
          zhanxing: $('#zhanxing').val(),
          zhishi: $('#zhishi').val()
        }
      } else if (geo_dim === '地市' || geo_dim === '区县') {
        this.param = {
          geo_dim: '区县',
          time_dim: shiduan,
          city: city,
          area: area !== '全量小区' ? area : '',
          zhanxing: $('#zhanxing').val(),
          zhishi: $('#zhishi').val()
        }
      }
      this.getWideData('netWork/geographyChart')
    },
    timeChart: function (shiduan, geo_dim, city, area) {
      if (geo_dim === '省') {
        this.param = {
          geo_dim: geo_dim,
          time_dim: shiduan,
          area: area,
          num: shiduan === 'M' ? 6 : 7,
          zhanxing: $('#zhanxing').val(),
          zhishi: $('#zhishi').val()
        }
      } else {
        this.param = {
          geo_dim: geo_dim,
          time_dim: shiduan,
          city: city,
          area: area,
          num: shiduan === 'M' ? 6 : 7,
          zhanxing: $('#zhanxing').val(),
          zhishi: $('#zhishi').val()
        }
      }
      this.getWideData('netWork/timeChart')
    },
    /* getWideData (param, reqUrl) {
      console.log('时间维度:' + param.time_dim + '；地理纬度:' + param.geo_dim + '；省:' + HB_province + '；市:' + param.city + '；区县:' + param.area + '；请求地址:' + reqUrl)
      service.get(getApiPath() + reqUrl,
        {
          params: this.param
        }
      ).then(function (res) {
        cleanRes()
        let res1 = res.data.a_pm_manager_view_widetable_new_list
        let a_pm_lte_manager_view_list = res.data.a_pm_lte_manager_view_list
        if (a_pm_lte_manager_view_list.length >= 1) {
          /!* if(isSetBaseVal(reqUrl)){
              setBaseVal(res);
          } *!/
          for (let i = a_pm_lte_manager_view_list.length - 1; i > -1; i--) {
            if (a_pm_lte_manager_view_list[i].city != '不详' && a_pm_lte_manager_view_list[i].area != '不详') {
              setVal(a_pm_lte_manager_view_list[i])
            }
          }
        }
        if (res1.length >= 1) {
          for (let i = res1.length - 1; i > -1; i--) {
            if (res1[i].city != '不详' && res1[i].area != '不详') {
              setVal1(res1[i])
            }
          }
        }
        setCalculateVal(reqUrl, this.param, res)
        drawPage()
      }).catch(function (e) {
        console.log(e)
        return false
      })
    }, */
    /* 获取数据 */
    getWideData (reqUrl) {
      this.$server.getData(
        reqUrl, this.param
      ).then(res => {
        console.log(res)
      })
    },
    check (val, el) {
      if (val > 0) {
        el.next('i').removeClass('fa-long-arrow-up').removeClass('fa-long-arrow-down').addClass('fa-long-arrow-up').css('color', '#f83608')
      } else if (val < 0) {
        el.next('i').removeClass('fa-long-arrow-up').removeClass('fa-long-arrow-down').addClass('fa-long-arrow-down').css('color', '#46d51a')
      } else {
        el.next('i').removeClass('fa-long-arrow-up').removeClass('fa-long-arrow-down')
      }
    },
    cleanRes () {
      this.volte_voice_traffic = []
      this.upoct = []
      this.starttime = []
      this.geoDim = []
      this.starttime1 = []
      this.geoDim1 = []
      this.high_load_num = []
      this.basic_comm_complain_ratio = []
      this.poor_coverage_cell_ratio = []
      this.mr_coverage_rate = []
      this.critical_alarm_ratio = []
      this.volteVoiceTraffic_upoct_JSON = {}

      this.lte_users = []
      this.lte_users_dou = []
      this.radio_use_rate = [] // LTE无限利用率
      this.upoct_aver = [] // 单小区流量
      this.volte_voice_traffic_aver = []

      this.wireless_access_rate = []
      this.ho_succ_rate = []
      this.wireless_dropcall_rate = []

      this.wireless_access_1_rate = []
      this.ho_succ_qci1_rate = []
      this.erab_dropcall_1_rate = []

      this.radio_equipment_availability = []
    },
    setBaseVal (res) {
      $('#baseSiteNums').html(this.viewCommon.toThousands(res[0].site_num_lte))// 基站数
      $('#cellNums').html(this.viewCommon.toThousands(res[0].cell_num_lte))// 小区数
      $('#hige_interfere_num_growthrate').html(this.viewCommon.toThousands(res[0].hige_interfere_num_growthrate) + '%')// 高干扰小区环比
      $('#high_interfer_num').html(this.viewCommon.toThousands(res[0].high_interfer_num))// 高干扰小区数
      $('#bad_cell_num_growthrate').html(this.viewCommon.toThousands(res[0].bad_cell_num_growthrate) + '%')// 劣化小区环比
      $('#bad_cell_num').html(this.viewCommon.toThousands(res[0].bad_cell_num))// 劣化小区数
      $('#lte_users').html(this.viewCommon.toThousands(res[0].lte_users))// 4G客户数
      $('#lte_users_dou').html(this.viewCommon.toThousands(res[0].lte_users_dou))// 4G客户DOU
      $('#bbu_online_rate').html(this.viewCommon.toThousands(res[0].bbu_online_rate))// BBU在网率
      // $('#radio_equipment_availability').html(this.viewCommon.toThousands(res[0].radio_equipment_availability));//无线设备可用率
      $('#upoct_chain').html(this.isNull(res[1].upoct_chain))// 流量 环比
      this.check(res[1].upoct_chain, $('#upoct_chain'))

      $('#upoct_yearOnYear').html(this.isNull(res[1].upoct_yearOnYear))// 流量 同比比
      this.check(res[1].upoct_yearOnYear, $('#upoct_yearOnYear'))
      $('#volte_voice_traffic_chain').html(this.isNull(res[1].volte_voice_traffic_chain))// 话务量 环比
      this.check(res[1].volte_voice_traffic_chain, $('#volte_voice_traffic_chain'))
      $('#volte_voice_traffic_yearOnYear').html(this.isNull(res[1].volte_voice_traffic_yearOnYear))// 话务量 同比
      this.check(res[1].volte_voice_traffic_yearOnYear, $('#volte_voice_traffic_yearOnYear'))

      // 单小区
      $('#upoct_aver_chain').html(this.isNull(res[1].upoct_aver_chain))// 流量 环比
      this.check(res[1].upoct_aver_chain, $('#upoct_aver_chain'))

      $('#upoct_aver_yearOnYear').html(this.isNull(res[1].upoct_aver_yearOnYear))// 流量 同比比
      this.check(res[1].upoct_aver_yearOnYear, $('#upoct_aver_yearOnYear'))
      $('#volte_voice_traffic_aver_chain').html(this.isNull(res[1].volte_voice_traffic_aver_chain))// 话务量 环比
      this.check(res[1].volte_voice_traffic_aver_chain, $('#volte_voice_traffic_aver_chain'))
      $('#volte_voice_traffic_aver_yearOnYear').html(this.isNull(res[1].volte_voice_traffic_aver_yearOnYear))// 话务量 同比
      this.check(res[1].volte_voice_traffic_aver_yearOnYear, $('#volte_voice_traffic_aver_yearOnYear'))

      // 无线和高负荷小区
      $('#high_load_num_chain').html(this.isNull(res[1].high_load_num_chain))// 高负荷  环比
      this.check(res[1].high_load_num_chain, $('#high_load_num_chain'))

      $('#high_load_num_yearOnYear').html(this.isNull(res[1].high_load_num_yearOnYear))// 高负荷 同比比
      this.check(res[1].high_load_num_yearOnYear, $('#high_load_num_yearOnYear'))

      $('#radio_use_rate_chain').html(this.isNull(res[1].radio_use_rate_chain))// 无线环比
      this.check(res[1].radio_use_rate_chain, $('#radio_use_rate_chain'))
      $('#radio_use_rate_yearOnYear').html(this.isNull(res[1].radio_use_rate_yearOnYear))// 无线 同比
      this.check(res[1].radio_use_rate_yearOnYear, $('#radio_use_rate_yearOnYear'))

      $('#wireless_access_rate').html(this.viewCommon.returnFloat(res[0].wireless_access_rate))
      $('#ho_succ_rate').html(this.viewCommon.returnFloat(res[0].ho_succ_rate))
      $('#wireless_dropcall_rate').html(this.viewCommon.returnFloat(res[0].wireless_dropcall_rate))
      $('#wireless_access_1_rate').html(this.viewCommon.returnFloat(res[0].wireless_access_1_rate))
      $('#ho_succ_qci1_rate').html(this.viewCommon.returnFloat(res[0].ho_succ_qci1_rate))
      $('#erab_dropcall_1_rate').html(this.viewCommon.returnFloat(res[0].erab_dropcall_1_rate))
    },
    setBaseVal1 (res1) {
      $('#baseSiteNums').html(res1 ? this.viewCommon.toThousands(res1[0].site_num_lte) : '0')// 基站数
      $('#cellNums').html(res1 ? this.viewCommon.toThousands(res1[0].cell_num_lte) : '0')// 小区数
      $('#lte_users').html(res1 ? this.viewCommon.toThousands(res1[0].lte_users) : '0')// 4G客户数
      $('#lte_users_dou').html(res1 ? this.viewCommon.toThousands(res1[0].lte_users_dou) + '(MB)' : '0')// 4G客户DOU
      $('#unlimited_lte_users').html(res1 ? this.viewCommon.toThousands(res1[0].unlimited_lte_users) : '0')// 4G不限量客户数(万)
      $('#radio_equipment_availability').html(this.viewCommon.toThousands(parseFloat(res1[0].radio_equipment_availability).toFixed(2)))// 无线设备可用率
    },
    setBaseVal2 (res1) {
      $('#baseSiteNums').html(res1 ? this.viewCommon.toThousands(res1[0].site_num_lte_lte) : '0')// 基站数
      $('#cellNums').html(res1 ? this.viewCommon.toThousands(res1[0].cell_num_lte_lte) : '0')// 小区数
    },
    isNull (data) {
      if (data === '') {
        return '无数据'
      } else {
        return data + '%'
      }
    },
    setCalculateVal (reqUrl, param, res) {
  if (reqUrl.indexOf('geographyChart') !== -1 && param.geo_dim === '区县' && param.city && !param.area && param.zhanxing === '全量小区' && param.zhishi === '全量小区') {
    let special_list = res.special_list
    $('#province_upoct_percent').html('(' + special_list[0].province_upoct_percent + '%)')
    $('#province_volte_voice_traffic_percent').html('(' + special_list[0].province_volte_voice_traffic_percent + '%)')
    $('#province_upoct_aver_percent').html('(' + parseFloat(special_list[0].province_upoct_aver_percent).toFixed(2) + 'GB)')
    $('#province_volte_voice_traffic_aver_percent').html('(' + parseFloat(special_list[0].province_volte_voice_traffic_aver_percent).toFixed(2) + 'Erl)')
    $('#province_radio_use_rate_percent').html('(' + special_list[0].province_radio_use_rate_percent + '%)')
    $('#province_high_load_num_percent').html('(' + special_list[0].province_high_load_num_percent + '%)')
    $('#province_radio_equipment_availability_percent').html('(' + special_list[0].province_radio_equipment_availability_percent + '%)')
    $('#province_lte_users_percent').html('(' + special_list[0].province_lte_users_percent + '%)')
    $('#province_unlimited_lte_users_percent').html('(' + special_list[0].province_unlimited_lte_users_percent + '%)')
    $('.targetHidden').removeAttr('hidden')
  } else {
    $('.targetHidden').attr('hidden', 'hidden')
  }
},

    setVal (item) {
      this.volte_voice_traffic.push(parseFloat(item.volte_voice_traffic))
      this.upoct.push(parseFloat(item.upoct))
      this.starttime.push(item.starttime.substr(5, 5))
      this.item.area === '全量小区' ? this.geoDim.push(item.city) : this.geoDim.push(item.area)
      this.high_load_num.push(parseInt(item.high_load_num))
      // basic_comm_complain_ratio.push(parseFloat(item.basic_comm_complain_ratio));
      this.mr_coverage_rate.push(parseFloat(item.mr_coverage_rate))
      this.poor_coverage_cell_ratio.push(parseFloat(item.poor_coverage_cell_ratio))
      this.critical_alarm_ratio.push(parseFloat(item.critical_alarm_ratio))

      this.lte_users.push(parseInt(item.lte_users))
      this.lte_users_dou.push(parseInt(item.lte_users_dou))
      this.radio_use_rate.push(parseFloat(item.radio_use_rate))
      let test = ((parseFloat(item.upoct) * 1000) / parseFloat(item.cell_num_lte))
      // test =  test.toFixed(2);
      test = Math.round(test * 100) / 100
      this.upoct_aver.push(test) // 单小区流量  parseFloat(upoct)/parseFloat(item.cell_num_lte)

      this.volte_voice_traffic_aver.push(Math.round(parseFloat(item.volte_voice_traffic) * 10000 / parseFloat(item.cell_num_lte) * 100) / 100)

      this.wireless_access_rate.push(parseFloat(item.wireless_access_rate))
      this.ho_succ_rate.push(parseFloat(item.ho_succ_rate))
      this.wireless_dropcall_rate.push(parseFloat(item.wireless_dropcall_rate))

      this.wireless_access_1_rate.push(parseFloat(item.wireless_access_1_rate))
      this.ho_succ_qci1_rate.push(parseFloat(item.ho_succ_qci1_rate))
      this.erab_dropcall_1_rate.push(parseFloat(item.erab_dropcall_1_rate))
    },
    setVal1 (item) {
      this.starttime1.push(item.starttime.substr(5, 5))
      this.basic_comm_complain_ratio.push(parseFloat(item.basic_comm_complain_ratio))
      item.area === '全量小区' ? this.geoDim1.push(item.city) : this.geoDim1.push(item.area)
      this.radio_equipment_availability.push(parseFloat(item.radio_equipment_availability))
    },
    drawPage () {
      // 流量话务量
      this.volteVoiceTraffic_upoct_JSON = {
        id: 'line1',
        title: null,
        cate: $('#showFont').attr('geography') ? this.geoDim : this.starttime,
        data: [
          {
            name: 'LTE数据流量(TB)',
            type: 'column',
            maxPointWidth: 10,
            // color: N.Util.Theme_colors.blue,
            data: this.upoct,
            yAxis: 0
          }, {
            name: 'VOLTE话务量(万Erl)',
            type: 'line',
            marker: {
              enabled: true, /* 数据点是否显示 */
              radius: 4 /* 数据点大小px */
            },
            // color: N.Util.Theme_colors.orange,
            data: this.volte_voice_traffic,
            yAxis: 1
          }
        ],
        marginTop: 30,
        marginBottom: 0,
        itemWidth: 110,
        lenabled: true,
        lenabledAlign: 'center',
        lenabledVerticalAlign: '',
        layout: 'horizontal',
        lenabledWidth: 10,
        chartType: 'column',
        // Yfloor: Math.max.apply(Math, upoct) * 0.2,
        Yfloor2: Math.max.apply(Math, this.volte_voice_traffic) * 0.2

      }
      this.drawColumnCol(this.volteVoiceTraffic_upoct_JSON)
      // 单小区流量,单小区VOLTE话务量
      this.drawColumnCol({
        id: 'line5',
        title: null,
        cate: $('#showFont').attr('geography') ? this.geoDim : this.starttime,
        data: [
          {
            name: '单小区流量(GB)',
            type: 'column',
            maxPointWidth: 10,
            // color: N.Util.Theme_colors.blue,
            data: this.upoct_aver,
            yAxis: 0
          }, {
            name: '单小区VOLTE话务量(Erl)',
            type: 'line',
            marker: {
              enabled: true, /* 数据点是否显示 */
              radius: 4 /* 数据点大小px */
            },
            // color: N.Util.Theme_colors.orange,
            data: this.volte_voice_traffic_aver,
            yAxis: 1
          }
        ],
        marginTop: 30,
        marginBottom: 35,
        itemWidth: 110,
        lenabledAlign: 'center',
        lenabledVerticalAlign: '',
        layout: 'horizontal',
        lenabled: true,
        // Yfloor: Math.max.apply(Math, upoct_aver) * 0.2,
        Yfloor2: Math.max.apply(Math, this.volte_voice_traffic_aver) * 0.2


      })

      // 严重告警小区占比--名称改为->严重告警基站占比-->无线设备可用率
      this.drawColumnColMax({
        id: 'line3',
        title: 'LTE无线设备可用率(%)',
        cate: $('#showFont').attr('geography') ? this.geoDim1 : this.starttime1,
        data: [
          {
            name: 'LTE无线设备可用率(%)',
            type: 'areaspline',
            // color: N.Util.Theme_colors.blue,
            fillOpacity: 0.3, // 指定面积图的透明度
            marker: {
              enabled: true,
              symbol: 'circle',
              radius: 2
            },
            data: this.radio_equipment_availability
          }
        ],
        marginTop: 30,
        marginBottom: 35,
        itemWidth: 110,
        lenabled: false,
        lenabledAlign: 'center',
        lenabledVerticalAlign: 'bottom',
        layout: 'horizontal',
        Yfloor: 95, // Math.max.apply(Math, radio_equipment_availability) * 0.95,
        YMax: 100
      })


      // LTE无线利用率和高负荷小区
      this.drawColumnCol({
        id: 'line4',
        title: null,
        cate: $('#showFont').attr('geography') ? this.geoDim : this.starttime,
        data: [
          {
            name: 'LTE无线利用率(%)',
            type: 'column',
            maxPointWidth: 10,
            // color: N.Util.Theme_colors.blue,
            data: this.radio_use_rate,
            yAxis: 0
          }, {
            name: '高负荷小区',
            type: 'line',
            marker: {
              enabled: true, /* 数据点是否显示 */
              radius: 4 /* 数据点大小px */
            },
            // color: N.Util.Theme_colors.orange,
            data: this.high_load_num,
            yAxis: 1
          }
        ],
        marginTop: 30,
        marginBottom: 35,
        itemWidth: 110,
        lenabledAlign: 'center',
        lenabledVerticalAlign: '',
        layout: 'horizontal',
        lenabled: true
        // Yfloor2: Math.max.apply(Math, high_load_num) * 0.6
        // Yceiling: Math.max.apply(Math, high_load_num)
      })
      // 基础通信万投比
      this.drawColumnCol({
        id: 'line6',
        title: '基础通信万投比',
        cate: $('#showFont').attr('geography') ? this.geoDim1 : this.starttime1,
        XWidth: 1,
        YWidth: 0,
        data: [
          {
            name: '基础通信万投比(%)',
            type: 'areaspline',
            // color: N.Util.Theme_colors.blue,
            fillOpacity: 0.3, // 指定面积图的透明度
            marker: {
              enabled: true,
              symbol: 'circle',
              radius: 2
            },
            data: this.basic_comm_complain_ratio,
            zones: [ {
              value: 0.15
              // color: N.Util.Theme_colors.blue
            }, {
              color: N.Util.Theme_colors.alarmRed
            }
            ]
          }
        ],
        marginTop: 30,
        marginBottom: 35,
        itemWidth: 110,
        lenabled: false,
        lenabledAlign: 'center',
        lenabledVerticalAlign: 'bottom',
        layout: 'horizontal'
      })
    }
},
  created: function () {
    // this.$emit('setHeader', false)
    // this.pageInit(this.geography, this.shiduan, this.geo_dim, this.map_city, this.map_area)
    this.pageInit('', 'D', '省', undefined, '全量小区')
  },
  mounted () {
  }
}

// $(function () {
//     $(document).on('map:click', function (event, geography, shiduan, geo_dim, map_city, map_area) {
//         page.pageLoad(geography, shiduan, geo_dim, map_city, map_area)
//     })
//     // page.pageLoad('','D', '省', undefined, '全量小区');
// })
